package com.servlet;

import com.model.Student;

import java.sql.*;


public class Main1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Main1 main1 = new Main1();
        main1.selectStudentById(2);

    }
    public void selectStudentById(int selectId) throws ClassNotFoundException, SQLException {

            Class.forName("com.mysql.cj.jdbc.Driver");

            String url ="jdbc:mysql://localhost:3306/web";
            String username = "root";
            String password = "666666";
            Connection connection = DriverManager.getConnection(url, username, password);

            String sql = "select*from t_student where id = ?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1,selectId);


            ResultSet resultSet = preparedStatement.executeQuery();

            while(resultSet.next()){
                int id = resultSet.getInt("id");
                String stuName = resultSet.getString("stu_name");
                String stuGender = resultSet.getString("stu_gender");
                Date stuBirther = resultSet.getDate("stu_birthday");
                String styAccount = resultSet.getString("stu_account");
                String stuPassword = resultSet.getString("stu_password");
                Student student = new Student(id, stuName, stuGender, stuBirther, styAccount, stuPassword);
                System.out.println(student);
            }


        }
    }
